﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace RTS
{
	public class Camera
	{
		private const float movementMarginThick = 30;	// px
		private const float velocity = 10;

		private float scale = 0.7F;
		private Vector2 cornerPos;

		public Vector2 CornerPos
		{
			get { return cornerPos; }
		}

		public float Scale
		{
			get { return scale; }
		}

		public Camera()
		{
			cornerPos = new Vector2(100, 100);
		}

		public void update(GraphicsDeviceManager graphics)
		{
			MouseState mouse = Mouse.GetState();
			float verticalRightLine = graphics.PreferredBackBufferWidth - movementMarginThick;
			float horizontalRightLine = graphics.PreferredBackBufferHeight - movementMarginThick;

			if (mouse.Y < movementMarginThick && mouse.X < movementMarginThick) // Upper left corner
			{
				cornerPos.X -= velocity;
				cornerPos.Y -= velocity;
			}
			else if (mouse.Y < movementMarginThick && mouse.X > verticalRightLine) // Upper right corner
			{
				cornerPos.X += velocity;
				cornerPos.Y -= velocity;
			}
			else if (mouse.Y < movementMarginThick) // Up
			{
				cornerPos.Y -= velocity;
			}
			else if (mouse.X < movementMarginThick && mouse.Y > horizontalRightLine) // Lower left corner
			{
				cornerPos.X -= velocity;
				cornerPos.Y += velocity;
			}
			else if (mouse.X < movementMarginThick) // Left
			{
				cornerPos.X -= velocity;
			}
			else if (mouse.Y > horizontalRightLine && mouse.X > verticalRightLine) // Lower right corner
			{
				cornerPos.X += velocity;
				cornerPos.Y += velocity;
			}
			else if (mouse.Y > horizontalRightLine) // Down
			{
				cornerPos.Y += velocity;
			}
			else if (mouse.X > verticalRightLine) // Right
			{
				cornerPos.X += velocity;
			}
		}
	}
}
